<?php

class UploadController extends Controller
{
	public $allowedExtsImage = array("gif", "jpeg", "jpg", "png");
	public $allowedExtsFile = array("zip");
	
	public function actionExtract(){
		if(Yii::app()->user->isGuest){
			jsonOut(array(
				'error'=>true,
				'message'=>'Pls login'
			));
		}
		if(!empty($_POST)){
			$id = Yii::app()->request->getParam('id',null);
			$zip = Yii::app()->zip;
			$project = Projects::model()->findByPk(outBin($id));
			if(empty($project)){
				jsonOut(array('error'=>true,'message'=>'Project not found'));
			}
			$name = $_POST['name'];
			$path = "projects/".outStr(currentUser(true)->id) ."/".$project->name."/";
			$zip->extractZip("projects/zip/".$name, $path); 
			
			
			
			$zip->extractZip("projects/source/source.zip", "projects/source/".outStr(currentUser(true)->id) ."/".$project->name."/"); 
			
			
			@mkdir("$path/lib", 0700);
			$zip->extractZip("projects/zip/".$name,"projects/source/".outStr(currentUser(true)->id) ."/".$project->name."/lib"); 
			
			//remove file project.zip
			@unlink( "projects/zip/".$name );
			
			$p = Projects::model()->gets();
			jsonOut(array('error'=>false,'to'=>"",'message'=>'Save ok','data'=>$p));
		
		}else{
			jsonOut(array(
				'error'=>true,
				'message'=>'Bad request'
			));
		}
	}
	public function actionFile(){
	
	

		$id = Yii::app()->request->getParam('pid',null);
		if(Yii::app()->user->isGuest){
			jsonOut(array(
				'error'=>true,
				'message'=>'Pls login'
			));
		}
		
		
		error_reporting(E_ALL | E_STRICT);
		try{
		
			$upload_handler = new UploadHandler();
			

			
		
		
		}catch(Exception $e){
			jsonOut(array(
				'error'=>true,
				'message'=>$e->getMessages()
			));
		}
		
		
		

		
		
	}
	
	
}